;---------------------------------------------
; flde v0.1 Fasmlab Disassembler Engine 32 bit
; ----------    BSD License   ----------------
; Copyright (c) 2009, Marc Rainer Kranz
; All rights reserved
;---------------------------------------------
;- SVN Repository at
;- http://code.google.com/p/flde/
;---------------------------------------------
;--- compile with fasm
; fasm test_32.asm
;--- execute
; test_32 > output.txt
;---------------------------------------------

format PE CONSOLE 4.0
entry start

include "win32a.inc"
section '.idata' import data readable writeable
	library msvcrt,"MSVCRT.DLL"
  import msvcrt,\
		printf,"printf"

section ".code" code readable executable
	include "flde32.asm"
	
	start:
	mov ebx,end_code - flde32_getlen
	mov eax,flde32_getlen

.next_i:
	push eax
	call flde32_getlen
	sub ebx,ecx
	jle	.exit
	call printout
	add eax,ecx
	jmp	.next_i
.exit:
	ret 12

align 4
printout:
	;IN EAX=pinstr
	;IN ECX=len
	push eax
	push ebx
	push ecx
	push esi
	push edi

	add esp,-80h
	mov esi,eax
	mov edi,esp
	xor eax,eax
	mov ebx,ascihex
	push edi
	push ecx
	push esi

.poA:
	lodsb
	ror eax,4
	xlatb
	stosb
	xor al,al
	rol eax,4
	xlatb
	stosb
	mov al,20h
	stosb
	dec ecx
	jnz	.poA
	xor al,al
	stosb

	push szFormat
	cinvoke printf
	add esp,16

.exit_po:	
	sub esp,-80h

	pop edi
	pop esi
	pop ecx
	pop ebx
	pop eax
	ret 0
end_code:

align 4
	ascihex		db "0123456789ABCDEF"
	szFormat	db "%Xh:%.2d | %s",13,10,0



